﻿using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using WcsZz.Extend;
using wms_wpf.Apiservice;
using wms_wpf.Dto;
using wms_wpf.InPut;

namespace wms_wpf.DialogView
{
    /// <summary>
    /// Dialog4.xaml 的交互逻辑
    /// </summary>
    public partial class Dialog4 : UserControl
    {
        public Dialog4(string Name)
        {
            InitializeComponent();
            service=new UserService();
            this.Name = Name;
            FindOneUserInfo(Name);
        }
        private readonly MyUserService service;
        private void TextBox_PreviewTextInput(object sender, TextCompositionEventArgs e)
        {
            short val;
            if (!Int16.TryParse(e.Text, out val))
                e.Handled = true;
        }
        public string Name;
        private async void FindOneUserInfo(string Name)
        {
         Tuple<UserDto,bool> UserDtoTuple=   await service.FindOneUserInfo(Name);
            if (UserDtoTuple.Item2)
            {
                Moniker.Text = UserDtoTuple.Item1.Moniker;
                Email.Text = UserDtoTuple.Item1.Email;
                PhoneNumber.Text = UserDtoTuple.Item1.PhoneNumber;
            }
            
            
        }
        private void TextBox_PreviewKeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Space)
                e.Handled = true;
        }
        private async void Confirm_Click(object sender, RoutedEventArgs e)
        {
            InPut_UserService4 InPut=new InPut_UserService4();
            InPut.Moniker = Moniker.Text; 
            InPut.Email=Email.Text;
            InPut.PhoneNumber = PhoneNumber.Text;
            InPut.UserName = Name;
            InPut.NewUserName = NewUserName.Text;
            bool res=await service.UpdateUserInfo(InPut);
            if (res) EventAggregatorHelper.EventAggregator.SendMessage("修改成功！", "GetList_View_User");
      
        }

    
    }
}
